package com.swak.frame.dto.request;

import java.util.Map;

public class PagingRequest extends MapRequest {
	private static final long serialVersionUID = 1519523262072752866L;
	private int pageIndex;
	private int pageSize = 10;
	private int totalRows;

	public PagingRequest() {
	}

	public PagingRequest(Map<String, Object> params) {
		this.putAll(params);
		if (params.get("page") != null) {
			// 分页参数
			this.pageIndex = Integer.parseInt(params.get("page").toString());
			this.pageSize = Integer.parseInt(params.get("limit").toString());
			this.put("offset", (pageIndex - 1) * pageSize);
			this.put("page", pageIndex);
			this.put("limit", pageSize);
		}
	}

	public int getOffset() {
		return pageIndex > 0 ? ((pageIndex - 1) * pageSize) : 0;
	}

	public PagingRequest(int pageIndex, int pageSize) {
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
	}

	public int getPageIndex() {
		return this.pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public int getPageSize() {
		return this.pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalRows() {
		return this.totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}
	
	
	

	public int getTotalPages() {
		return new Integer(new Double(
				Math.ceil(new Double(this.totalRows).doubleValue() / new Double(this.pageSize).doubleValue()))
						.intValue()).intValue();
	}

}
